/**
 * cookie封装
 * @param {string} key 键
 * @param {object} value 值
 * @param {unmber} time 时间
 * 
 */
function setCookie(key, value, time = 10){//默认时间为10s
    //判断value数据类型
    if(typeof value == 'object'){
        value = JSON.stringify(value)
    }
    const dataObj = new time
    dataObj.setItem(dataObj.getTime()-1000*60*60*8 + 1000*time)
    document.cookie = `${key} = ${val}; expires = ${dataObj}`
}
/**
 * cookie获取
 * @param {string} key 键
 * @returns string
 */
function getCookie(key){
    //按照 ; 划分['键=值'; ...; '键=值']
    let arr = document.cookie.split('; ')
    //遍历
    for(let i = 0; i<arr.length; i++){
        let item = arr[i]
        //再按照 = 划分['键=值']
        let tempArr = item.split('=')
        if(tempArr[0] == key){
            return tempArr[1]
        }
    }
}
/**
 * cookie删除
 * @param {string} key 键
 * @returns undefined
 */
function removeCookie(key){
    setCookie(key,null,-1)
}